/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.sonar.util.ui;

import bgu.sonar.util.async.Callback;
import javax.swing.SwingUtilities;

/**
 * a callback that will be performed in the ui thread
 *
 * @author bennyl
 */
public abstract class UICallback<T> implements Callback<T> {

    @Override
    public final void onFailed(final Exception ex, final boolean interrupted) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                onFailedUI(ex, interrupted);
            }
        });
    }

    @Override
    public final void onSuccess(final T res) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                onSuccessUI(res);
            }
        });
    }

    public abstract void onFailedUI(Exception ex, boolean interrupted);

    public abstract void onSuccessUI(T res);
}
